/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.util.ArrayList;
import constants.*;
public class RoomController {
    public static boolean insert(entity.Room room){
        return new dao.Room().addRoom(room.getName(),room.getType(),room.getStatus());
    }
    public static boolean update(int id, entity.Room room){
        return new dao.Room().updateRoom(id, room.getName(),room.getType(),room.getStatus());
    }
    public static boolean remove(int id){
        return new dao.Room().deleteRoom(id);
    }
    
    public static boolean updateStatus(int idroom, int status){
        return new dao.Room().updateStatus(idroom, status);
    }
    public static void updateStatusInList(ArrayList<entity.Room> list, int status){
          for(int i=0;i<list.size();i++){
                updateStatus(list.get(i).getId(),status);              
                System.out.println("Đã thay đổi trạng thái phòng "+list.get(i).getName()+" sang "+Constants.STATUS_NAME[status]);
            }
    
    }
    public static void removeFromListBooking(int id){
            ArrayList<entity.Room> list = BookingController.getRoomByCustomer(id); 
            updateStatusInList(list,Constants.EMPTY);
            BookingController.remove(id);
            
    }
    public static void insertToListBooking(int id,ArrayList<entity.Room> room){
             for(int i=0;i<room.size();i++){
                            if(BookingController.insert(room.get(i).getId(), id))
                            System.out.println("Đã thêm phòng "+room.get(i).getName());
                            if(RoomController.updateStatus(room.get(i).getId(), Constants.BOOKING))
                            System.out.println("Đã thay đổi trạng thái phòng "+room.get(i).getName()+" sang "+Constants.STATUS_NAME[Constants.BOOKING]);
            }
    }
    public static boolean isRoomExist(int id,String nameRoom){
        return new dao.Room().isRoomNameExist(id,nameRoom);
    }
    public static int countRoomByStatus(int status){
        return new dao.Room().countByStatus(status);
    }
    public static ArrayList<entity.Room> getAll(){
        return new dao.Room().getAllRoom();
    }
    public static ArrayList<entity.Room> getAllByType(int type){
        return new dao.Room().getAllRoomByType(type);
    }
    public static ArrayList<entity.RoomType> getAllType(){
        return new dao.RoomType().getAllType();
    }
     public static boolean insertType(entity.RoomType type){
        return new dao.RoomType().addType(type.getName(),type.getCost(), type.getInfo());
    }
    public static boolean updateType(int id, entity.RoomType type){
        return new dao.RoomType().updateType(id,type.getName(),type.getCost(), type.getInfo());
    }
    public static boolean removeType(int id){
        return new dao.RoomType().deleteType(id);
    }
 
    
    
}
